package io.renren.modules.generator.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.generator.entity.SheeppriceEntity;
import io.renren.modules.generator.service.SheeppriceService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;




/**
 * 
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-04-10 14:50:38
 */
@RestController
@RequestMapping("sheepprice")
public class SheeppriceController {
	@Autowired
	private SheeppriceService sheeppriceService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("sheepprice:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<SheeppriceEntity> sheeppriceList = sheeppriceService.queryList(query);
		int total = sheeppriceService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(sheeppriceList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("sheepprice:info")
	public R info(@PathVariable("id") Integer id){
		SheeppriceEntity sheepprice = sheeppriceService.queryObject(id);
		
		return R.ok().put("sheepprice", sheepprice);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("sheepprice:save")
	public R save(@RequestBody SheeppriceEntity sheepprice){
		sheeppriceService.save(sheepprice);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("sheepprice:update")
	public R update(@RequestBody SheeppriceEntity sheepprice){
		sheeppriceService.update(sheepprice);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("sheepprice:delete")
	public R delete(@RequestBody Integer[] ids){
		sheeppriceService.deleteBatch(ids);
		
		return R.ok();
	}
	@RequestMapping("/timelist")
	@RequiresPermissions("sheepprice:list")
	public R timelist(@RequestParam Map<String, Object> params){
		//查询列表数据
	    Query query = new Query(params);
		String starttime =params.get("starttime").toString();
		String endtime =params.get("endtime").toString();
		
//		System.out.println(starttime);
//		System.out.println(endtime);

		List<SheeppriceEntity> sheeppriceList = sheeppriceService.timeList(query);
		int total = sheeppriceService.timeTotal(query);
		
		PageUtils pageUtil = new PageUtils(sheeppriceList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
		//return R.ok(starttime);
	}
	
}
